package com.xhg.util.mail;

import java.util.Properties;

import com.xhg.common.Constants;
import com.xhg.util.propUtil.Prop;
import com.xhg.util.propUtil.PropertiesUtil;

/**
 * 发送邮件需要使用的基本信息
 * createTime 2014-12-17
 * @author wjw
 */
public class MailSenderInfo {
	/**
	 * 静态块初始化邮件服务器设置
	 */
	static{
		Prop prop=PropertiesUtil.loadProperty("config/param.properties",Constants.DEFAULT_ENCODING);
		mailServerHost=prop.get("mail.smtp.host");//邮件服务ip或域名
		mailServerPort=prop.get("mail.smtp.port");//邮件服务器端口号
		userName=prop.get("mail.smtp.user");//登陆邮件系统的用户名
		password=prop.get("mail.smtp.password");//登陆邮件系统的密码
	}
	/** 发送邮件的服务器的IP和端口 */
	public static String mailServerHost;
	public static String mailServerPort;
	/** 登陆邮件发送服务器的用户名 */
	public static String userName;
	/** 登陆邮件发送服务器的密码 */
	public static String password;
	
	/** 邮件接收者的地址 */
	public String[] toAddress;
	/** 抄送人地址 */
	public String[] ccAddress;
	/** 密送人地址 */
	public String[] bccAddress;

	/** 是否需要身份验证 */
	public boolean validate = true;
	/** 邮件主题 */
	public String subject;
	/** 邮件的文本内容 */
	public String content;
	/** 邮件附件的文件名 */
	public String[] attachFileNames;
	SimpleMailSender sms = new SimpleMailSender();
	
	/** 获得邮件会话属性 */
	public Properties getProperties() {
		Properties p = new Properties();
		p.put("mail.smtp.host", mailServerHost);
		p.put("mail.smtp.port", mailServerPort);
		p.put("mail.smtp.user", userName);
		p.put("mail.smtp.password", password);
		p.put("mail.smtp.auth", validate ? "true" : "false");
		return p;
	}

	/** 发送邮件 */
	public void sendMail() {
		this.sms.sendHtmlMail(this);
	}
/*********************************************************/
	
	
	
	
	
	public String getMailServerHost() {
		return mailServerHost;
	}

	public static void setMailServerHost(String mailServerHost) {
		MailSenderInfo.mailServerHost = mailServerHost;
	}

	public static void setMailServerPort(String mailServerPort) {
		MailSenderInfo.mailServerPort = mailServerPort;
	}

	public static void setUserName(String userName) {
		MailSenderInfo.userName = userName;
	}

	public static void setPassword(String password) {
		MailSenderInfo.password = password;
	}

	public String getMailServerPort() {
		return mailServerPort;
	}

	public boolean isValidate() {
		return validate;
	}

	public void setValidate(boolean validate) {
		this.validate = validate;
	}

	public String[] getAttachFileNames() {
		return attachFileNames;
	}

	public void setAttachFileNames(String[] fileNames) {
		this.attachFileNames = fileNames;
	}

	public String getPassword() {
		return password;
	}

	public String[] getToAddress() {
		return toAddress;
	}

	public void setToAddress(String[] toAddress) {
		this.toAddress = toAddress;
	}

	public String getUserName() {
		return userName;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String textContent) {
		this.content = textContent;
	}

	public String[] getCcAddress() {
		return ccAddress;
	}

	public void setCcAddress(String[] ccAddress) {
		this.ccAddress = ccAddress;
	}

	public String[] getBccAddress() {
		return bccAddress;
	}

	public void setBccAddress(String[] bccAddress) {
		this.bccAddress = bccAddress;
	}

}